package git.oschina.dushougudu.processor;

import com.google.common.base.Charsets;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;

public class SpringServicesFiles {
    static void writeServiceFile(Map<String, Set<String>> services, OutputStream output) throws IOException {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, Charsets.UTF_8));
        for (Map.Entry<String, Set<String>> entry : services.entrySet()) {
            writer.write(entry.getKey() + "=\\");

            boolean first = true;
            for (String service : entry.getValue()) {
                if (first) {
                    writer.newLine();
                    writer.write(service);
                    first = false;
                } else {
                    writer.write(",\\");
                    writer.newLine();
                    writer.write(service);
                }
            }
            writer.newLine();
        }
        writer.flush();
    }

}
